package com.chu.demo;

public class DeadLock extends Thread{

    private final String stringA;

    private final String stringB;


    public DeadLock(String name, String stringA, String stringB) {
        super(name);
        this.stringA = stringA;
        this.stringB = stringB;
    }

    @Override
    public void run() {
        synchronized (stringA){
            System.out.println("ThreadName:"+this.getName()+"获取:"+stringA);
            try {
                Thread.sleep(1000);
                synchronized (stringB){
                    System.out.println("进不来");
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

class Test{
    public static void main(String[] args) {
        String stringA = "aaaaaaa";
        String stringB = "bbbbbbb";
        DeadLock d1 = new DeadLock("ThreadA",stringA,stringB);
        DeadLock d2 = new DeadLock("ThreadB",stringB,stringA);
        d1.start();
        d2.start();
    }
}